import logging
from fastapi import APIRouter, Query
from fastapi.exceptions import HTTPException

from app.controllers.user import user_controller, UserController
from app.core.dependency import DependPermission
from app.schemas.base import Fail, Success, SuccessExtra
from app.schemas.users import *

logger = logging.getLogger(__name__)

router = APIRouter()


@router.get("/list", summary="获取用户列表", dependencies=[DependPermission])
async def get_list():
    result = await user_controller.model.all()
    return Success(data=result)


@router.post("/update", summary="更新用户信息", dependencies=[DependPermission])
async def update_user(user_in: UserUpdate):
    user_controller = UserController()
    result = await user_controller.update(id=user_in.id, obj_in=user_in)
    return Success(data=result)


@router.post("/create", summary="创建用户", dependencies=[DependPermission])
async def create_user(user_in: UserCreate):
    user_controller = UserController()
    result = await user_controller.create(obj_in=user_in)
    return Success(data=result, msg="更新成功")
